<?php 
define('PAGE_NEED_PRI','PRI_EDIT');
session_start();include "conn.php";
?>
<?php  include("admin.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Bios 管理中心 </title>
<link href="../css/control.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.5.2.min.js"  language="javascript" ></script>

<link href="../css/crop/jquery.Jcrop.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery.Jcrop.min.js"  language="javascript" ></script>

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
 <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>

<script src="uploadify/swfobject.js"  language="javascript" ></script>
<script src="uploadify/jquery.uploadify.v2.1.4.min.js"  language="javascript" ></script>
<link href="uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<style>
.ui-dialog .ui-dialog-titlebar-close 
{
	text-align:left;
}
</style>

<script src="../js/calendar.js"  language="javascript" ></script>

<script language="javascript">
$(function(){
				//init file upload
				$(".uploadifyupload").each(function(){
					var current_id = $(".uploadifyupload").attr('id');
					var previous_img_id = current_id + '_img';
					$(".uploadifyupload").uploadify({
						'uploader': 'uploadify/uploadify.swf',
						'cancelImg': 'uploadify/cancel.png',
						'script': 'upload.php',
						'folder': 'files',
						'buttonText':'Choose',
						'multi': false,
						'fileExt':'*.jpg;*.jpeg;*.gif;*.png',
  						'fileDesc':'Image Files',
						'auto': true,
						'queueSizeLimit':1,
						'scriptData':{'<?php echo session_name();?>':'<?php echo session_id();?>','responsetype':'sizeinfo'},
						'displayData': 'speed',
						'onComplete':function(event,queueID,fileObj,response,data){
							var responseObj = eval("("+response+")");
							var fileName = responseObj.name;
							var i_width = responseObj.w;
							var i_height = responseObj.h;
							var i_show_height = 300;
							var i_scale = i_show_height/i_height;
							var i_show_width = i_width*i_scale;
							
							var crop_width = 142;
							var crop_height = 110;
							var crop_show_width = crop_width*i_scale;
							var crop_show_height = crop_height*i_scale;
							
							
							var crop_box_x = (i_show_width - crop_show_width)/2;
							var crop_box_y = (i_show_height - crop_show_height)/2;
							
						
							var select_x;
							var select_y;
							var select_w;
							var select_h;
							
						  $('#'+previous_img_id).attr('src','../upfiles/tmp/' + fileName);
						  $('input[name=ajaxf_'+current_id+']').val(fileName);
											
							$( "#cropdialog").dialog({
							 	'width':i_show_width + 50,
							 	'height':i_show_height + 128,
								buttons:[{'text':'OK','click':function(){
									p_src = "tmp/" + fileName;
									var crop_file_name = fileName + "."+crop_width+"x"+crop_height+".jpg";
									p_des = "tmp/" + crop_file_name;
									
									p_width = crop_width;
									p_height = crop_height;
									p_c_x = select_x/i_scale;
									p_c_y = select_y/i_scale;
									p_c_width = select_w/i_scale;
									p_c_height = select_h/i_scale;
			
									$.post("crop.php", {'src': p_src,'des':p_des,'width':p_width,'height':p_height,'c_x':p_c_x,'c_y':p_c_y,'c_width':p_c_width,'c_height':p_c_height},function(date){							
										$( "#cropdialog").html('');
										$( "#cropdialog").dialog("destroy");
									});

								}}]
							});
							$( "#cropdialog").html("<img src='../upfiles/tmp/"+fileName+"' id='cropbox' width='"+i_show_width+"' height='"+i_show_height+"'/> ");
							$('#cropbox').Jcrop({ 
							onSelect:function(c){
								select_x = c.x;
								select_y = c.y;
								select_w = c.w;
								select_h = c.h;							
								
							},
							/*setSelect:[crop_box_x, crop_box_y,crop_box_x + crop_show_width, crop_box_y + crop_show_height],*/
							aspectRatio:crop_width/crop_height});
						},
						'onError':function(event,queueId,fileObj,errorObj){
							alert(errorObj);
						}
					});
				});
				
				
				

});
</script>

</head>

<body>
<div id="cropdialog" title="Crop image"></div>
<a name="top" id="top"></a>
<div id="all"><!--Wrap start //-->
<div id="main" class="clearfix"><!--main start //-->
<div id="top-1"><?php include_once('blog_top_btn.php');?>
</div>
<!--Content for  id "submenu" Goes Here //-->
<div id="submenu">
<?php include_once('admin_main_btn.php');?>
  </div>
 <!--Content for  id "contact" Goes Here //-->
 <div id="contact">


<?php 
//修改数据
$id=make_safe($_GET["id"]);
$action=make_safe($_GET["action"]);
$username=make_safe($_GET["username"]);
$password=make_safe($_POST["password"]);
$name=make_safe($_POST["name"]);
$tel=make_safe($_POST["tel"]);
$email=make_safe($_POST["email"]);
$msn=make_safe($_POST["msn"]);
$address=make_safe($_POST["address"]);
$oldimages=make_safe($_POST["oldimages"]);
$content=$_POST["content"];
include("check.php");

if($action=="xiugai"){


if($id!=""){
$images = $_REQUEST['ajaxf_images'];

$update_column_sql = "password='$password',name='$name',tel='$tel',email='$email',msn='$msn',address='$address',content='$content',";

if(strlen($images) > 0)
{
	//Move horizen image
	$srcPath = dirname(dirname(__FILE__)).'/upfiles/tmp/'.$images.'.142x110.jpg';
	$tarPath = dirname(dirname(__FILE__)).'/upfiles/'.$images.'.142x110.jpg';
	copy($srcPath,$tarPath);
	unlink($srcPath);
	//move vetical image
	$srcPath = dirname(dirname(__FILE__)).'/upfiles/tmp/'.$images;
	$tarPath = dirname(dirname(__FILE__)).'/upfiles/'.$images;
	copy($srcPath,$tarPath);
	unlink($srcPath);
	
	$tarPath = $_REQUEST['ajaxf_images'];
	$update_column_sql  .= "images='$tarPath',";
}
if(isset($_REQUEST['lock']))
	{
		//check lacok max number
		$check_sql = sprintf("SELECT count(1) AS `co` FROM `guanli` WHERE   `lock`='Y' AND `id` != %d",$id);
		$check_result=mysql_query($check_sql);
			if($check_result == false)
			{
				$error = sprintf("%s%s%s",mysql_error(),__FILE__,__LINE__);
				echo $error;
				exit();
			}
			$check_info =mysql_fetch_assoc($check_result);
			if($check_info['co'] > 4)
			{
				echo "<script>alert('鎖定失敗,最多鎖定五個作者');window.location.href='admin-acc-e-main.php';</script>";
				exit();
			}
			
		$lock = 'Y';
		$update_column_sql .= sprintf("`lock_start`='%s',",mysql_real_escape_string($_REQUEST['lock_start']));
		$update_column_sql .= sprintf("`lock_end`='%s',",mysql_real_escape_string($_REQUEST['lock_end']));
	}else{
		$lock = '';
	}
$update_column_sql .= "`lock`='$lock',";

$update_column_sql = substr($update_column_sql,0,-1);
$sql = sprintf("UPDATE `guanli` SET %s WHERE id=%d",$update_column_sql,$id);
if($query=mysql_query($sql))

{
if($_SESSION["PRI_ADMIN"]==1 ){
   echo "<script>alert('資料修改成功！');window.location.href='admin-acc-e-main.php';</script>";
   }else{
    echo "<script>alert('資料修改成功！');window.location.href='admin-acc-e-main.php?id=".$id."';</script>";
	}
 }
 
 else
  {
  
  echo mysql_error();
  exit();
  if($_SESSION["PRI_ADMIN"]==1){
   echo "<script>alert('資料修改失敗！');window.location.href='admin-acc-e-main.php';</script>";
      }else{
   echo "<script>alert('資料修改失敗！');window.location.href='admin-acc-e-main.php?id=".$id."';</script>";
   }
   
  }
  }
   }


?>







<table width="98%" border="0" >
  <tr>
    <td>個人賬號管理 - 管理員管理 - 修改密碼 </td>
  </tr>
</table></br>

        
<form name="form1" action="?action=xiugai&id=<?php echo $id;?>" method="post"    enctype="multipart/form-data"  target="_self" >
              <table width="98%" border="1" cellpadding="0" cellspacing="0" bgcolor="#000000" >
              
<?php 
    $sql="select * from guanli where id='$id' ";	
	$result=mysql_query($sql);
	while ($row=mysql_fetch_array($result)){
	?>
	
	
	 <tr > 
     <td width="28%" height="25" > 
                  <div align="center">管理員帳號：</div></td>
                  <td width="28%" > 
                  <div align="center"><?php echo $row["username"];?></div></td>
                  <td width="24%" > 
                  <div align="center">操作</div></td>
                </tr>
	
	
				
				
				 <tr > 
                  <td height="22" > 
                    <div align="center">
                   姓名：                  </div></td>
                  <td > 
                    <div align="center">
                      <input type="text" name="name" value="<?php echo $row["name"];?>">
                  </div></td>
                  <td > 
                   <div align="center"></div></td>
                </tr>
				
				
				
				
				
				 <tr > 
                  <td height="22" > 
                    <div align="center">
                   郵件：                  </div></td>
                  <td > 
                    <div align="center">
                      <input type="text" name="email" value="<?php echo $row["email"];?>">
                  </div></td>
                  <td >                </td>
                </tr>
				
				
				
				<tr > 
                  <td height="22" > 
                    <div align="center">
                  MSN：                  </div></td>
                  <td > 
                    <div align="center">
                      <input type="text" name="msn" value="<?php echo $row["msn"];?>">
                  </div></td>
                  <td >                </td>
                </tr>
				
				
				 <tr > 
                  <td height="22" > 
                    <div align="center">
                   電話：                  </div></td>
                  <td > 
                    <div align="center">
                      <input type="text" name="tel" value="<?php echo $row["tel"];?>">
                  </div></td>
                  <td > 
                   <div align="center"></div></td>
                </tr>
				
				
				
				
				 <tr > 
                  <td height="22" > 
                    <div align="center">
                   個人網址：                  </div></td>
                  <td > 
                    <div align="center">
                      <input type="text" name="address" value="<?php echo $row["address"];?>">
                  </div></td>
                  <td > 
                    <div align="center"></div></td>
                </tr>
				
				 <?php
 	if($row['lock_start'] == '0000-00-00 00:00:00')
 	{
 		$row['lock_start'] = date('Y-m-d');
 	}
 	if($row['lock_end'] == '0000-00-00 00:00:00')
 	{
 		$row['lock_end'] = date('Y-m-d');
 	}
 ?>
				 <tr > 
                  <td height="22" > 
                    <div align="center">
                   鎖定：                  </div></td>
                  <td colspan="2"> 
                    <div align="center">
                       <input type="checkbox" name="lock" <?php if($row['lock'] == 'Y'):?>checked="checked"<?php endif;?>/>
                       &nbsp;&nbsp;鎖定時間：<input name="lock_start" type="text" style="width:80px" onfocus="c.showMoreDay = false;c.show(this,'<?php echo date('Y-m-d',strtotime($row['lock_start']));?>');" value="<?php echo date('Y-m-d',strtotime($row['lock_start']));?>">
                        &nbsp;&nbsp;<input name="lock_end" type="text" style="width:80px" onfocus="c.showMoreDay = false;c.show(this,'<?php echo date('Y-m-d',strtotime($row['lock_end']));?>');" value="<?php echo date('Y-m-d',strtotime($row['lock_end']));?>">
                  </div></td>
                  
                </tr>
						
				<tr > 
                  <td height="22" > 
                    <div align="center">
                  個人圖像：                  </div></td>
                  <td > 
                  <div align="center">
                  <input type="hidden" name="ajaxf_images" value=""/>
                  <input name="images" id="images" type="file" size="50"   class="uploadifyupload"/>  
                   <td > 
                           <?php if(strlen($row['images']) > 0):?>
 				<img id="images_img" id="images_img" src="../upfiles/<?php echo $row['images'];?>" width="35" height="35" />
 		<?php else:?>
 						<img id="images_img" id="images" src="../upfiles/upfiles/default.png" width="35" height="35" />
 
 		<?php endif;?>
                    <div align="center">
	
		
		</div></td>
                </tr>
				
				
				
				
				
				
				<tr > 
                  <td height="22" > 
                    <div align="center">
                  個人簡介：                  </div></td>
                  <td colspan="2" > 
                    <div align="center">
                      <?php 
include('../fckeditor/fckeditor.php');
	$oFCKeditor = new FCKeditor('FCKeditor1')  ; 
	$oFCKeditor->BasePath = '../fckeditor/' ;    
	$oFCKeditor->ToolbarSet = 'Default' ; 
	$oFCKeditor->InstanceName = 'content' ; 
	$oFCKeditor->Width = '100%' ; 
	$oFCKeditor->Height = '400' ; 
	//$oFCKeditor->Value  = $row['content']; 
	$oFCKeditor->Value  = $row["content"]; 
$oFCKeditor->Create();?>
                  </div> 
                  <div align="center"></div></td>
                </tr>
				
				
				
				
				<tr > 
                  <td height="22" > 
                    <div align="center">                 </div></td>
                  <td > 
                    <div align="center">
                      <input type="submit" name="submit2" value="修改" />
                    </div></td>
                  <td > 
                    <div align="center"></div></td>
                </tr>
				
				
				
<?php }?>
  </table>
</form>









   

   
   
   
   
   
 </div>
  <!--Content for  id "contact_page" Goes Here //-->
  
</div><!-- main end //-->
</div><!--Wrap end //-->
<div id="botton">
 <?php include_once('admin_botton_btn.php');?>
</div>

<script language="javascript">
<!--

function ConfirmDel()
{
   if(confirm("確定要刪除選擇的項目嗎？一旦刪除將不能恢複！"))
     return true;
   else
     return false;	 
}


</SCRIPT>

<script language="javascript">
	function check(form1){
		if(form1.username.value==""){
			alert("请输入管理員帳號!");form1.username.focus();return false;		
		}
		if(form1.password.value==""){
			alert("请输入管理員密碼!");form1.password.focus();return false;
		}
		
		if(form1.password.value!=form1.conpassword.value){
			alert("對不起，您輸入的確認密碼不正確!");form1.conpassword.focus();return false;
		}
	}
</script>



</body>
</html>
